package user_assets_ewallet

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/base-common/headInfo"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/types"
	"github.com/zeromicro/go-zero/core/logx"
)

type UserEWalletUpdateInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 更新
func NewUserEWalletUpdateInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserEWalletUpdateInfoLogic {
	return &UserEWalletUpdateInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserEWalletUpdateInfoLogic) UserEWalletUpdateInfo(req *types.UserEWalletsUpdateRequest) (resp *types.UserEWalletsUpdateResponse, err error) {
	_, err = l.svcCtx.AssetsRpc.UserChannel.UserEWalletsUpdate(l.ctx, &rpc.UserEWalletsUpdateRequest{
		UserId:   headInfo.GetTokenUid(l.ctx),
		Name:     req.WalletName,
		Username: req.Username,
		Account:  req.Account,
	})
	if err != nil {
		return &types.UserEWalletsUpdateResponse{
			IsUpdate: false,
		}, nil
	}
	return &types.UserEWalletsUpdateResponse{
		IsUpdate: true,
	}, nil
}
